
function init()
{
  if (wave && wave.isInWaveContainer())
  {
    wave.setStateCallback(stateUpdated);
  }
}

function stateUpdated()
{
  alert("starting");
  updateSolutionsTable();
  alert("updated");
}

function updateSolutionsTable()
{
  // if (!wave.getState()) { return; }
  
  // var wave = wave.getState();
  // var keys = state.getKeys();
  var solutionsTable = "<ul>";
  
  //for (var i = 0; i < keys.length; ++i)
  //{
    //solutionsTable += "<li>" + keys[i] + " : " + state.get(keys[i]) + "</li>";
  //}
  
  solutionsTable += "</ul>";
  alert(solutionsTable);
  // document.getElementById("solutionsTable").innerHTML = solutionsTable;
}

function submitSolution()
{
  var viewerId = wave.getViewer().getId();
  var solutionKey = "solution_" + viewerId;
  var solution = document.getElementById("mySolution").value;
  wave.getState().submitDelta( { solutionKey : solution } );
}

gadgets.util.registerOnLoadHandler(init);